//
//	File: OyDirect3D9_MaterialSystem.h
//

#ifndef OYDIRECT3D9_MATERIALSYSTEM_H
#define OYDIRECT3D9_MATERIALSYSTEM_H

#include "DataStruct/OyDataStruct.h"

struct OYSKIN_TYPE;
class AbstractMaterial;

class OyMaterialSystem
{
public:
	enum GameMaterial
	{
		eMaterial_opaque_base = 0,
		eMaterial_opaque_alphatest,
		eMaterial_transparent,

		eMaterial_line,
		eMaterial_font,

		eMaterial_Custom,
		eMaterial_Unknow,
	};

	enum GameModifier
	{
		eModifier_withlight = 0,
		eModifier_nolight,
		eModifier_wireframe,

		eModifier_Unknow,
	};

	struct D3D9MaterialInfo
	{
		D3D9MaterialInfo();
		D3D9MaterialInfo( char* MaterialStr );
		void CloneMaterial( const D3D9MaterialInfo& _MaterialInfo );
		void Reset();
		AbstractMaterial *m_material;
	};

	typedef OyArrayStack<D3D9MaterialInfo>	MaterialList;

public:
	static const int INIT_MATERIALLIST_BEGIN_NUM = 32;
	inline static OyMaterialSystem* GetInstance()
	{
		static OyMaterialSystem staticInstance;
		return &staticInstance;
	}

	OyMaterialSystem() :	m_materials(INIT_MATERIALLIST_BEGIN_NUM), 
							m_modifiers(INIT_MATERIALLIST_BEGIN_NUM) { }
	~OyMaterialSystem();

	void	AddMaterial( char* MaterialStr );
	void	AddModifier( char* ModifierStr );
	void	AddMaterial( struct D3D9MaterialInfo *pNewMaterialInfo );
	void	AddModifier( struct D3D9MaterialInfo *pNewModifierInfo );

	void	LoadGameMaterials();
	void	LoadCustomMaterials( char* MaterialStr );
	void	CommitAdditionalMaterial(const struct D3D9MaterialInfo& MT, const struct OYSKIN_TYPE* pSkin );
	void	UpdateTextureMaterial(const struct D3D9MaterialInfo& MT, unsigned int texID, int unit);
	void	UpdateDynamicMaterials( float elapsedTime );

	// Interface
	inline	MaterialList& GetMaterialList() { return m_materials; }
	inline	MaterialList& GetModifierList() { return m_modifiers; }

private:
	MaterialList	m_materials;
	MaterialList	m_modifiers;
};

#define	GetOyMaterialSystem()	OyMaterialSystem::GetInstance()

#endif